package jlib.component.button
{
	import flash.display.DisplayObject;
	import flash.display.LineScaleMode;
	import flash.display.Sprite;
	import flash.text.TextFormat;
	
	import jlib.component.core.LabelBox;
	import jlib.core.collection.HashMap;
	import jlib.core.geom.Bound;

	/**
	 * size 조정은 가급적이면, setLabelSize로
	 * @author 안형로
	 */
	public class LabelButton extends SkinButton
	{
		private var m_label:String;
		private var m_button:SkinButton;
		private var m_map:Object;

		public function LabelButton($label:String=null): void {
			buildDefault();
			setLabel($label);
		}

		override public function setSkin($state:String, $value:DisplayObject): void {
			var labelBox:LabelBox = m_map[$state] as LabelBox;
			labelBox.setBackground($value);
		}
		
		private function buildDefault($width:Number=LabelButtonFactory.DEFAULT_WIDTH,$height:Number=LabelButtonFactory.DEFAULT_HEIGHT): void {
			m_map = LabelButtonFactory.order(LabelButtonFactory.DEFAULT_ORDER,$width,$height,m_label);
			buildAction();
		}
		
		private function buildDisable($width:Number=LabelButtonFactory.DEFAULT_WIDTH,$height:Number=LabelButtonFactory.DEFAULT_HEIGHT): void {
			m_map = LabelButtonFactory.order(LabelButtonFactory.DISABLE_ORDER,$width,$height,m_label);
			buildAction();
		}
		
		private function buildAction():void {
			setWrappee(this);
			super.setSkin(ButtonState.UP, m_map.up );
			super.setSkin(ButtonState.DOWN, m_map.down );
			super.setSkin(ButtonState.ROLLOVER, m_map.rollOver );
			super.setSkin(ButtonState.ROLLOUT, m_map.rollOut );
		}
		
		public function getLabel(): String { return m_label; }
		public function setLabel($label:String, $status:String='all'): void {
			if($label == null) return ;
			m_label = $label;
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setLabel($label);
			else m_map[$status].setLabel($label);
		}
		
		public function setFontSize($size:uint, $status:String='all'):void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setFontSize($size);
			else m_map[$status].setFontSize($size);
		}
		
		public function setFont($fontName:String, $status:String='all'): void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setFont($fontName);
			else m_map[$status].setFont($fontName);
		}
		
		public function setFontColor($color:uint, $status:String='all'): void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setFontColor($color);
			else m_map[$status].setFontColor($color);
		}
		
		public function setEmbedFonts($boolean:Boolean, $status:String='all'): void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setEmbedFonts($boolean);
			else m_map[$status].setEmbedFonts($boolean);
		}
		
		public function setSize($width:Number, $height:Number, $status:String='all'): void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setSize($width, $height);
			else m_map[$status].setSize($width, $height);
		}
		
		public function setRound($round:int, $status:String='all'): void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setRound($round);
			else m_map[$status].setRound($round);
		}

		public function setBorder($border:int, $borderColor:uint=0x000000, $type:String='solid', $position:String="middle", $scaleMode:String = LineScaleMode.NONE, $dashSize:Number=3, $gapSize:Number=3, $status:String='all'): void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setBorder($border,$borderColor,$type,$position,$scaleMode,$dashSize, $gapSize);
			else m_map[$status].setBorder($border,$borderColor,$type,$position,$scaleMode, $dashSize, $gapSize);
		}

		public function setLabelAlign($textFormatAlign:String, $status:String='all'): void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setAlign($textFormatAlign);
			else m_map[$status].setAlign($textFormatAlign);
		}

		public function setLabelAutoSize($textFieldAutoSize:String, $status:String='all'): void {
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setAutoSize($textFieldAutoSize);
			else m_map[$status].setAutoSize($textFieldAutoSize);
		}

		public function setLabelSize($width:Number, $height:Number, $status:String='all'): void
		{
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setSize($width, $height);
			else m_map[$status].setSize($width, $height);
		}

		public function setTextFormat($value:TextFormat, $status:String='all'): void
		{
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setFormat($value);
			else m_map[$status].setFormat($value);
		}

		public function setPadding($padding:Bound, $status:String='all'): void
		{
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setPadding($padding);
			else m_map[$status].setPadding($padding);
		}

		public function setBackground($value:*, $status:String='all'): void
		{
			if($status == ButtonState.ALL) for each(var box:LabelBox in m_map) box.setBackground($value);
			else m_map[$status].setBackground($value);
		}
		
		override public function set width($width:Number): void {
			for each(var box:LabelBox in m_map){
				box.width = $width;
			}
		}
		
		override public function set height($height:Number): void {
			for each(var box:LabelBox in m_map){
				box.height = $height;
			}
		}
		
		public function isEmptyLabel(): Boolean  { return (getLabel() == '' || !getLabel());  }

	}//c
}